﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Tradex.Messages;

namespace Tradex.Market {

    /// <summary>
    /// This class represents all the data of an instrument. It is a dynamically updating
    /// object (when fed with update messages).
    /// </summary>
    [Serializable ()]
    public sealed class Instrument : ComponentModel.DynamicObject {

        /// <summary>
        /// The public constructor, taking the InstrumentKey as parameter.
        /// </summary>
        /// <param name="key"></param>
        public Instrument(InstrumentKey key) {
            Key = key;
        }

        /// <summary>
        /// Constructor for a specific instrument. Returns a pointer to the (internal) update processing method.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="inputAction"></param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021")]
        public Instrument(InstrumentKey key, out Action<Message> inputAction)
            : base(out inputAction)
        {
                Key = key;
        }

        /// <inheritdoc />
        public override void ProcessMessage(Message message) {
        }

        /// <summary>
        /// The InstrumentKey that identifies the instrument.
        /// </summary>
        public InstrumentKey Key { get; private set; }

        /// <summary>
        /// The mostl static instrument basic information is stored in this property.
        /// </summary>
        public InstrumentInfo Info {
            get {
                lock (this) {
                    return _Info;
                }
            }
            set {
                lock (this) {
                    OnPropertyChanged("Info", ref _Info, value);
                }
            }
        }
        InstrumentInfo _Info;

        /// <summary>
        /// This property contains pricing information for the instrument.
        /// </summary>
        public InstrumentPricing Pricing {
            get {
                lock (this) {
                    return _Pricing;
                }
            }
            set {
                lock (this) {
                    OnPropertyChanged("Pricing", ref _Pricing, value);
                }
            }
        }
        InstrumentPricing _Pricing;

    }

}
